#include "netim.h"
#include "SettingManager.h"
#include "initialsettings.h"

#include <QtGui>
#include <QApplication>
#include <QTranslator>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // Translation Routine
    // this sentences will only work if tt2_es.qm is in the resource
    QTranslator translator( 0 );
    QFile archivo(":/translation/tt2_es.qm");
    archivo.open(QIODevice::ReadOnly);
    QByteArray translatstream = archivo.readAll();
    // Until here

    translator.load((const uchar*)translatstream.data(), translatstream.size());
    a.installTranslator( &translator );
    SettingManager settings;
    // willset says if the initialsettings dialog will be shown
    bool willset = false;
    // willshow says if the mainwindow will be shown
    bool willshow = false;
    if (settings.first_time)
    {
    	// Msgbox of first time
    	willset = true;
    } else {
    	willset = !(settings.valid());
    	willshow = !willset;
    	// If willset msgbox error
    }
    while (willset)
    {
    	initialsettings initdialog(0, settings.alias,
    		settings.path_rsa, settings.path_agn);
    	if (!initdialog.exec()) {
    		// Pressed cancel: exit
    		willset = false;
    		willshow = false;
    	} else {
    		// Pressed OK: check and try again if needed
    		willset = !(settings.valid_or_null(&initdialog));
    		// If not needed show
    		willshow = true;
    	}
    }
    settings.Save();
    QApplication::setQuitOnLastWindowClosed(false);
    netim w(&settings);
    if (willshow) w.show(); else exit(0);
    return a.exec();
}

